<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDeviceOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('device_orders', function (Blueprint $table) {
            $table->unsignedBigInteger('id')->primary();
            $table->unsignedBigInteger('user_id')->default(0)->comment('发布者')->index('user');
            $table->unsignedBigInteger('pay_user_id')->default(0)->comment('支付人')->index('pay_user');
            $table->unsignedBigInteger('delivery_user_id')->default(0)->comment('发货人')->index('delivery_user');
            $table->unsignedBigInteger('receipt_user_id')->default(0)->comment('收货人')->index('receipt_user');
            $table->integer('quantity')->default(0)->comment('设备数量');
            $table->unsignedBigInteger('device_group_id')->nullable()->default(0)->comment('订单关联群组 可以为空')->index('group');
            $table->unsignedBigInteger('factory_user_id')->nullable()->default(0)->comment('厂家ID')->index('factory');
            $table->string('transfer_voucher',255)->nullable()->default('')->comment('转账凭证');
            $table->string('ship_voucher',255)->nullable()->default('')->comment('发货凭证');
            $table->string('refund_voucher',255)->nullable()->default('')->comment('退款凭证');
            $table->string('receipt_voucher',255)->nullable()->default('')->comment('收货凭证');
            $table->unsignedBigInteger('cost_total_price')->nullable()->default(0)->comment('成本总价(分)');
            $table->unsignedBigInteger('cost_unit_price')->nullable()->default(0)->comment('成本单价');
            $table->integer('before_profit')->nullable()->default(0)->comment('盈利前分成比例 10000计');
            $table->integer('after_profit')->nullable()->default(0)->comment('盈利后分成比例 10000计');
            $table->integer('original_price')->nullable()->default(0)->comment('下单设备原价');
            $table->integer('discount_price')->nullable()->default(0)->comment('下单设备折扣价');
            $table->unsignedBigInteger('total_sales_amount')->default(0)->comment('订单设备累计创收总金额(分)');
            $table->dateTime('factory_time')->nullable()->comment('出厂时间');
            $table->dateTime('payment_time')->nullable()->comment('付款时间');
            $table->dateTime('receipt_time')->nullable()->comment('收货时间');
            $table->dateTime('cancle_time')->nullable()->comment('取消时间');
            $table->enum('style',['TEA_HOUSE','INTERNET_CAFE'])->nullable()->default('INTERNET_CAFE')->comment('款式 TEA_HOUSE茶楼 INTERNET_CAFE网吧');
            $table->string('receiver')->nullable()->default('')->comment('收货人');
            $table->string('receiving_call')->nullable()->default('')->comment('收货电话');
            $table->string('shipping_address')->nullable()->default('')->comment('收货地址');
            $table->string('shipping_address_detail')->nullable()->default('')->comment('收货详细地址');
            $table->string('sender')->nullable()->default('')->comment('发货人');
            $table->string('shipping_call')->nullable()->default('')->comment('发货电话');
            $table->string('delivery_address')->nullable()->default('')->comment('发货地址');
            $table->string('delivery_address_detail')->nullable()->default('')->comment('发货详细地址');
            $table->string('create_remark')->nullable()->default('')->comment('创建备注');
            $table->string('pay_remark')->nullable()->default('')->comment('付款备注');
            $table->string('ship_remark')->nullable()->default('')->comment('发货备注');
            $table->string('receipt_remark')->nullable()->default('')->comment('收货备注');
            $table->string('install_remark')->nullable()->default('')->comment('初装备注');
            $table->string('refund_remark')->nullable()->default('')->comment('退款备注');
            $table->enum('status',['WAIT_PAY','WAIT_DELIVERY','WAIT_RECEIPT','WAIT_INSTALL','COMPLETE','CANCEL'])->default('WAIT_PAY')->comment('状态 WAIT_PAY待付款 WAIT_DELIVERY待出厂 WAIT_RECEIPT待收货 WAIT_INSTALL待安装 COMPLETE订单完成CANCEL取消');
            $table->timestamps();
            $table->softDeletes();
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->engine = 'InnoDB';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('device_orders');
    }
}
